<?php
/**
* SessionController
*/
class SessionController {
	/**
	 * Singleton Instance
	 * 
	 * @access private
	 */
	private static $_instance;
	
	/**
	 * Atributos
	 * 
	 * @access private
	 */
	private $_attributes;
	
	/**
	 * Construtor Privado Singleton
	 * 
	 * @access private
	 */
	private function __construct() {
		session_start ();
		$this->_attributes = &$_SESSION;
	}
	
	/**
	 * Criador Singleton
	 * 
	 * @access public
	 */
	public static function getInstance() {
		if (is_null ( self::$_instance )) {
			self::$_instance = new self ();
		}
		return self::$_instance;
	}
	
	/**
	 * Retorna Atributo da Sess�o
	 * 
	 * @access public
	 */
	public function getAttribute($key) {
		if (isset ( $this->_attributes [$key] )) {
			return $this->_attributes [$key];
		}
		return null;
	}
	
	/**
	 * Seta Atributo na Sess�o
	 * 
	 * @access public
	 */
	public function setAttribute($key, $value) {
		if (is_null ( $key ) | empty ( $key ) | is_bool ( $key )) {
			throw new Exception ( 'A chave n�o deve ser do tipo v�zio, booleano ou nulo! ' . __METHOD__);
		}
		$this->_attributes [$key] = $value;
	}
	
	/**
	 * Elimina Atributo na Sess�o
	 * 
	 * @access public
	 */
	public function unsetAttribute($key) {
		unset ( $this->_attributes [$key] );
	}
	
	/**
	 * Elimina Toda a Sess�o
	 * 
	 * @access public
	 */
	public function clear() {
		session_destroy ();
	}
}
?>